#include "rendererManager.h"

RenderManager::RenderManager() {

}

void RenderManager::run() {
	while (running) {
		if (renderFrame) {
			renderFrameDone = false;

			frameTimer.start();

			renderViewTimer.start();
			renderView();
			renderViewTimer.stop();

			frameTimer.stop();

			renderFrame = false;
			renderFrameDone = true;
		} else {
			this->sleep(1);
		}
	}
}

void RenderManager::join() {
	running = false;
	this->stop();
}

bool RenderManager::setup(HWND hwnd, RenderOptions renderOptions) {
	this->renderOptions = renderOptions;
	
	if (!opengl.setup(hwnd)) {
		return false;
	}

	return true;
}

void RenderManager::reshapeWindow(int x, int y, int width, int height) {
#ifdef _WINDOWS
	opengl.reshapeWindow(x, y, width, height);
#endif
}

bool RenderManager::renderView() {
#ifdef _WINDOWS
	if (!opengl.renderView()) {
		return false;
	}
#endif

	return true;
}